//
//  SXStatusToolBar.swift
//  sina
//
//  Created by shengxinwei on 16/5/24.
//  Copyright © 2016年 shengxinwei. All rights reserved.
//

import UIKit
import SnapKit

class SXStatusToolBar: UIView {

    var statusViewModel: SXStatusViewModel? {
        didSet {
            repostBtn.setTitle(statusViewModel?.repostsText, forState: .Normal)
            commentBtn.setTitle(statusViewModel?.commentsText, forState: .Normal)
            likeBtn.setTitle(statusViewModel?.attitudesText, forState: .Normal)
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        backgroundColor = UIColor.whiteColor()
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setupUI() {
        addSubview(commentBtn)
        addSubview(repostBtn)
        addSubview(likeBtn)
        
        
        setupButton(commentBtn, title: "评论", imageName: "timeline_icon_comment")
        setupButton(repostBtn, title: "转发", imageName: "timeline_icon_retweet")
        setupButton(likeBtn, title: "赞", imageName: "timeline_icon_like")
        
        let line1 = lineView()
        let line2 = lineView()
        addSubview(line1)
        addSubview(line2)
        
        let width = UIScreen.mainScreen().scale
        commentBtn.snp_makeConstraints { (make) in
            make.left.top.bottom.equalTo(self)
        }
        repostBtn.snp_makeConstraints { (make) in
            make.left.equalTo(commentBtn.snp_right)
            make.top.bottom.equalTo(commentBtn)
            make.width.equalTo(commentBtn)
        }
        likeBtn.snp_makeConstraints { (make) in
            make.left.equalTo(repostBtn.snp_right)
            make.top.bottom.equalTo(commentBtn)
            make.right.equalTo(self.snp_right)
            make.width.equalTo(repostBtn.snp_width)
        }
        line1.snp_makeConstraints { (make) in
            make.left.equalTo(commentBtn.snp_right)
            make.centerY.equalTo(commentBtn)
            make.height.equalTo(commentBtn).multipliedBy(0.4)
            make.width.equalTo(width)
        }
        line2.snp_makeConstraints { (make) in
            make.left.equalTo(likeBtn.snp_left)
            make.centerY.equalTo(repostBtn)
            make.height.equalTo(repostBtn).multipliedBy(0.4)
            make.width.equalTo(width)
        }
        
        
    }
    
    
    private func lineView() -> UIView {
        let lineView = UIView()
        lineView.backgroundColor = UIColor.darkGrayColor()
        return lineView
    }
    
    private func setupButton(btn: UIButton,title: String,imageName: String) {
        btn.setTitle(title, forState: .Normal)
        btn.setBackgroundImage(UIImage(named: "timeline_card_bottom_background"), forState: .Normal)
        btn.setImage(UIImage(named: imageName), forState: .Normal)
        btn.titleLabel?.font = UIFont.systemFontOfSize(10.0)

        btn.setTitleColor(UIColor.darkGrayColor(), forState: .Normal)
    }
    
    //MARK: - 懒加载
    private lazy var commentBtn: UIButton = UIButton()
    private lazy var repostBtn: UIButton = UIButton()
    private lazy var likeBtn: UIButton = UIButton()
  

}
